import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

Vue.prototype.$enviorment = 'http://feicui.shangtianjs.com.cn'; 
Vue.prototype.$domain = Vue.prototype.$enviorment + '/api/'

Vue.prototype.$get = function(url,data,callback){
	uni.request({
		header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8','token':uni.getStorageSync('token') ||"" },
		url: this.$domain + url,
		dataType: 'json', //默认 json格式
		method: 'GET', //请求方式
		data:data,
		success: (res) => {
			var res = res.data;
			if(res.code == 1){
				callback(res.data)
			}else if(res.code == 401){
				uni.showModal({
				    title: '提示',
				    content: '当前页面需要授权登录，确认是否跳转登录？',
				    success: (res)=> {
				        if (res.confirm) {
				            uni.navigateTo({
				            	url: "/pages/my/login"
				            })
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			}else{
				uni.showToast({
					title:res.msg,
					icon:"none"
				})
			}
			
			// console.log(res.data);
		},
		fail: (error) => {
			console.log(error)
		}
	})
}

Vue.prototype.$post = function(url,data,callback){
	uni.request({
		url: this.$domain + url,
		dataType: 'json', //默认 json格式
		method: 'POST', //请求方式
		data:data,
		header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8','token':uni.getStorageSync('token') ||"" },
		success: (res) => {
			var res = res.data;
			if(res.code == 1){
				callback(res.data)
			}else if(res.code == 401){
				uni.navigateTo({
					url: "/pages/my/login"
				})
			}else{
				uni.showToast({
					title:res.msg,
					icon:"none"
				})
			}
		},
		fail: (error) => {
			console.log(error)
		}
	})
}



App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()
